<?php

namespace App\Services\MiniprogramToGame\HotSearch;

use App\Services\ServiceBase;
use App\Structs\HotSearchStruct;
use Illuminate\Support\Facades\Http;

class Bilibili extends ServiceBase
{
    public function reptile()
    {
        $url = 'https://app.bilibili.com/x/v2/search/trending/ranking';
        $response = Http::get($url);
        if (!$response->ok()) {
            return false;
        }

        $data = json_decode($response->body(), true);

        $list = [];
        foreach ($data['data']['list'] as $index => $item) {
            $class           = new HotSearchStruct;
            $class->title    = $item['keyword'];
            $class->desc     = $item['show_name'];
            $class->hotIndex = $item['position'];
            $class->hotValue = $item['hot_id'];
            $class->url      = "https://search.bilibili.com/all?keyword=".$item['keyword']."&order=click";
            $list[] = $class;
        }

        return $list;
    }
}
